﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace ChBusiness.Wsbs
{
    /// <!--
    /// 功能描述  : 网上办事操作类
    /// 创建人  : LinJian
    /// 创建时间: 2006-09-04
    /// -->
    public class WebWork 
    {
        private Database dbTemp = BasicOperate.CreateNetOfficeDataBase();

        /// <summary>
        /// 取出所有内容
        /// </summary>
        /// <returns></returns>
        public DataTable GetWorkFlow()
        {
            //添加已发布,和未删除的条件.edit by zhongjian 20091014
            string strSql = @"select * from XT_WORKFLOW_DEFINE where ispub='1' and isdelete='0' 
                order by FLOWNUM asc";
            DbCommand cmd = dbTemp.GetSqlStringCommand(strSql);

            return dbTemp.ExecuteDataSet(cmd).Tables[0];
        }

        /// <summary>
        /// Gets the work flow list.
        /// </summary>
        /// <param name="strFlowName">流程名</param>
        /// <returns></returns>
        public DataTable GetChildMenuRight(string strFlowName)
        {
            //添加已发布,和未删除的条件.edit by zhongjian 20091014
            string strSql = @"select a.id,
                       a.flowid,
                       a.menu_name,
                       a.menu_type,a.menu_appear,
                       b.flowname,
                       b.flowtype,
                       b.flownum
                  from xt_workflow_set a, xt_workflow_define b
                 where a.flowid = b.id
                   and b.ispub = '1'
                   and a.menu_appear = '1'
                   and b.isdelete = '0'";

            if (!string.IsNullOrEmpty(strFlowName))
            {
                strSql += string.Format(" and b.flowname='{0}' ",strFlowName);
            }
            strSql += " order by FLOWNUM asc";

            DbCommand cmd = dbTemp.GetSqlStringCommand(strSql);
            return dbTemp.ExecuteDataSet(cmd).Tables[0];
        }

        /// <summary>
        /// 根据流程名称获取流程图办理人员 显示类型
        /// </summary>
        /// <param name="strFlowName">流程名称</param>
        /// <returns></returns>
        /// <!--addby zhongjian 20091210-->
        public string GetIsShowDialog(string strFlowName)
        {
            string strSql = string.Format(@"select IsShowDialog  from xt_workflow_define
                            where ispub = 1 and isdelete = 0 and flowname = '{0}'", strFlowName);
            DbCommand cmd = dbTemp.GetSqlStringCommand(strSql);
            DataTable dtTemp= dbTemp.ExecuteDataSet(cmd).Tables[0];
            string strShowType=string.Empty;
            if (dtTemp.Rows.Count > 0)
                strShowType = dtTemp.Rows[0][0].ToString();
            return strShowType;
        }

        /// <summary>
        /// 根据流程名称获取WID
        /// </summary>
        /// <param name="strFlowName">流程名称</param>
        /// <returns></returns>
        /// <!--addby zhongjian 20091210-->
        public string GetWorkWid(string strFlowName)
        {
            string strSql = string.Format(@"select wid from st_workflow a where rot=0 and wname='{0}'", strFlowName);
            DbCommand cmd = dbTemp.GetSqlStringCommand(strSql);
            DataTable dtTemp = dbTemp.ExecuteDataSet(cmd).Tables[0];
            string strWid = string.Empty;
            if (dtTemp.Rows.Count > 0)
                strWid = dtTemp.Rows[0][0].ToString();
            return strWid;
        }
    }
}
